<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ lastNum }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          href="javascript:;"
          @click="changeType('all')"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'No' }"
          href="javascript:;"
          @click="changeType('No')"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'Done' }"
          href="javascript:;"
          @click="changeType('Done')"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clearAsync" v-show="showClear">
      清除已完成
    </button>
  </footer>
</template>

<script>
import { mapActions, mapGetters, mapMutations, mapState } from "vuex";
export default {
  computed: {
    ...mapState(["list", "type"]),
    // ...mapGetters(["lastNum"]),
    ...mapGetters(["newList"]),
    //剩余数量
    lastNum() {
      return this.newList.filter((item) => !item.isDone).length;
    },

    //清除已完成的显示判断
    showClear() {
      return this.newList.some((item) => item.isDone);
    },
  },
  methods: {
    ...mapMutations(["changeType"]),
    ...mapActions(["clearAsync"]),
  },
};
</script>
